Skip to content

Migrate bin bindings to new BindingGenerator trait#2880

Merged
messense merged 2 commits intoPyO3:mainfrom
e-nomem:bin-bindings
Dec 1, 2025
Merged

Migrate bin bindings to new BindingGenerator trait#2880
messense merged 2 commits intoPyO3:mainfrom
e-nomem:bin-bindings

Conversation

@e-nomem
Copy link
Copy Markdown
Contributor

@e-nomem e-nomem commented Nov 29, 2025

Updating the generator code required a few changes:

  • (minor) The BindingGenerator trait methods are now &mut self
  • (minor) Updated fn generate_bindings(..) to take &[&BuildArtifact] and loop over them now to handle multiple bin files
  • (important!) WheelWriter now defers writing the .dist-info until finish()

For that third change, there are two reasons for it:

  1. The BinBindingGenerator mutates the Metadata24 as each bin is processed, so we cannot write the entry_points.txt file until the end
  2. PEP 427 recommends that the .dist-info files be placed physically at the end of the archive (link)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the binary bindings code to use the BindingGenerator trait pattern, consolidating wheel writing logic and improving code organization. The key architectural change is deferring .dist-info writing in WheelWriter until finish() to allow generators to mutate metadata during artifact processing, which aligns with PEP 427 recommendations.

Key Changes

  • Introduced BinBindingGenerator implementing the BindingGenerator trait to handle binary artifacts, consolidating logic from the removed bin_wasi_helper function and write_bin function
  • Modified WheelWriter to defer writing .dist-info directory until finish(), moving pyproject_dir and tags parameters from constructor to finish() method
  • Updated BindingGenerator trait to use &mut self methods, allowing generators to maintain mutable state across artifact processing

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/module_writer/wheel_writer.rs Refactored to defer .dist-info writing from constructor to finish() method; updated test accordingly
src/build_context.rs Removed bin_wasi_helper function; updated all wheel writing methods to use new WheelWriter API; converted add_external_libs and add_rpath to use generic Borrow parameters for flexibility
src/binding_generator/wasm_binding.rs Deleted file - functionality migrated to bin_binding.rs
src/binding_generator/pyo3_binding.rs Updated generate_bindings method signature to &mut self
src/binding_generator/cffi_binding.rs Updated generate_bindings method signature to &mut self
src/binding_generator/bin_binding.rs New file implementing BinBindingGenerator with logic migrated from removed functions; handles binary artifact packaging and WASI launcher generation
src/binding_generator/mod.rs Updated BindingGenerator trait to use &mut self; modified generate_binding to accept slice of artifacts with generic Borrow parameter; removed write_bin function

Comment thread src/build_context.rs Outdated
Comment thread src/build_context.rs
Comment thread src/binding_generator/mod.rs Outdated
Comment thread src/binding_generator/bin_binding.rs Outdated
@messense messense enabled auto-merge (squash) December 1, 2025 02:58
@messense messense merged commit 2f56b8f into PyO3:main Dec 1, 2025
45 checks passed
@e-nomem e-nomem deleted the bin-bindings branch December 1, 2025 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants